<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			//输入: nums = [1,3,5,6], target = 5
			//输出: 2
			//输入: nums = [1,3,5,6], target = 2
			//输出: 1
			function searchInsert(nums, target){
				let left = 0;
				let right = nums.length - 1;
				while (left <= right){
					let mid = Math.floor((left + right)/2);
					if(nums[mid] == target){
						return mid;
					}else if (nums[mid] >= target){
						right = mid - 1;
					}else {
						left = mid + 1;
					}
				}
				return left;
			}
			console.log(searchInsert([1,3,5,6],5));
		</script>
	</body>
</html>
